﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>试题添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="weadmin-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="ETID" class="layui-form-label">
                    <span class="we-red">*</span>试题类型
                </label>
                <div class="layui-input-inline">
                    <select id="ETID" name="ETID" class="valid" lay-filter="ETID">
                        <!--<option value="0">请选择</option>-->
                    </select>
                </div>
                <label for="EQSubject" class="layui-form-label">
                    <span class="we-red">*</span>知识点
                </label>
                <div class="layui-input-inline">
                    <select id="EQSubject" name="EQSubject" class="valid"></select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="EQContent" class="layui-form-label">
                    <span class="we-red">*</span>问题
                </label>
                <div class="layui-input-block">
                    <textarea id="EQContent" name="EQContent" placeholder="请输入" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="EQScore" class="layui-form-label">
                    <span class="we-red">*</span>分数
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="EQScore" name="EQScore" lay-verify="required|number" autocomplete="off" class="layui-input">
                </div>
                <label for="EQIntegral" class="layui-form-label">
                    <span class="we-red">*</span>积分
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="EQIntegral" name="EQIntegral" lay-verify="required|number" autocomplete="off" class="layui-input">
                </div>
            </div>
            <!--<div class="layui-form-item">
                <label for="EQUseCount" class="layui-form-label">
                    <span class="we-red">*</span>使用次数
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="EQUseCount" name="EQUseCount" lay-verify="required|number" autocomplete="off" class="layui-input">
                </div>
                <label for="EQIsAutoMark" class="layui-form-label">给分方式</label>
                <div class="layui-input-inline" id="EQIsAutoMark">
                    <input type="radio" name="EQIsAutoMark" value="自动" title="自动" checked>
                    <input type="radio" name="EQIsAutoMark" value="人工" title="人工">
                </div>
            </div>-->
            <div class="layui-form-item" id="answerXuanZhe">
                <label for="EQAnswerCheck" class="layui-form-label">
                    <span class="we-red">*</span>答案
                </label>
                <div class="layui-input-inline">
                    <select id="EQAnswerCheck" name="EQAnswerCheck" class="valid">
                    </select>
                </div>
            </div>
            <div class="layui-form-item" id="answerJieDa">
                <label for="EQAnswer" class="layui-form-label">
                    <span class="we-red">*</span>答案
                </label>
                <div class="layui-input-block">
                    <textarea id="EQAnswer" name="EQAnswer" placeholder="请输入" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="EQContent" class="layui-form-label">
                </label>
                <button class="layui-btn" lay-filter="add" lay-submit="">添 加</button>
            </div>
        </form>
    </div>
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>

    <script>

        layui.use(['form', 'jquery', 'layer'], function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer;
            $.support.cors = true;
            $.ajaxSetup({
                cache: false,
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
            })

            //试题类型变更事件 显示对应的答案界面
            $("#answerJieDa").hide();
            //$("#answerXuanZhe").show();
            form.on('select(ETID)', function (data) {
                var currETID = data.value; //$("#ETID").val();
                if (currETID == 1 || currETID == 2) {
                    $("#answerJieDa").hide();
                    $("#answerXuanZhe").show();
                    $("#EQAnswerCheck").empty();
                    if (currETID == 1) {
                        $("#EQAnswerCheck").append("<option value='A'>A</option>");
                        $("#EQAnswerCheck").append("<option value='B'>B</option>");
                        $("#EQAnswerCheck").append("<option value='C'>C</option>");
                        $("#EQAnswerCheck").append("<option value='D'>D</option>");
                    }
                    else {
                        $("#EQAnswerCheck").append("<option value='对'>对</option>");
                        $("#EQAnswerCheck").append("<option value='错'>错</option>");
                    }
                    form.render();
                } else {
                    $("#answerJieDa").show();
                    $("#answerXuanZhe").hide();
                }
            });

            $(function () {
                //加载试题类型信息
                $.ajax({
                    url: ApiUrl + "ExamType/SelList",
                    type: 'post',
                    success: function (data) {
                        if (data.StatusCode == 200 && data.Count != 0) {
                            $(data.Data).each(function (index, item) {
                                $("#ETID").append("<option value='" + item.ETID + "'>" + item.ETName + "</option>");
                            });
                            form.render();
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                //加载知识点信息
                $.ajax({
                    url: ApiUrl + "KnowledgeKey/SelList",
                    type: 'post',
                    success: function (data) {
                        if (data.StatusCode == 200 && data.Count != 0) {
                            $(data.Data).each(function (index, item) {
                                $("#EQSubject").append("<option value='" + item.KKID + "'>" + item.KKName + "</option>");
                            });
                            form.render();
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });

            })
            //监听提交
            form.on('submit(add)', function (formdata) {
                formdata.field.EQAnswer = ($("#ETID").val() == 1 || $("#ETID").val() == 2) ? formdata.field.EQAnswerCheck : formdata.field.EQAnswer;
                if (formdata.field.EQAnswer == "") {
                    layer.msg("答案不能为空");
                    return;
                }
                $.ajax({
                    url: ApiUrl + "ExamQuestions/Add",
                    type: 'post',
                    dataType: 'json',
                    data: formdata.field,
                    success: function (data) {
                        if (data.StatusCode == 200 && data.Count != 0) {
                            layer.alert(data.Info, { icon: 6 }, function (index) {
                                parent.layer.closeAll();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                return false;
            });
        });
    </script>
</body>
</html>